package ocbn.remotelab.util;

/**
 * A class that converts numbers to strings and vice versa. 
 *
 * @author Ke Li
 */
public class NumberConverter {

    /**
     * Converts a string to a long integer.
     *
     * @param str   The string to be converted
     * @return      A long integer whose value corresponds to the string
     */

    public static long toLong(String str){
        if(str.startsWith("0x")){
            return Long.parseLong(str.substring(2), 16);
        }else{
            return Long.parseLong(str);
        }
    }

    /**
     * Converts a long integer to a string that contains its hexadecimal
     * representation. 
     *
     * @param num   A long integer to be converted
     * @return      A string that contains the long integer's hexadecimal
     *              representation
     */

    public static String toHexString(long num){
        return "0x" + Long.toString(num, 16);
    }

    /**
     * Converts a long integer to a string that contains its decimal (base-10)
     * representation.
     *
     * @param num   A long integer to be converted
     * @return      A string that contains the long integer's decimal
     *              representation
     */

    public static String toString(long num){
        return Long.toString(num);
    }

}
